package com.zhou.project.modules.circle.circlePostsYes.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhou.project.modules.circle.circleGroupPosts.entity.CircleGroupPosts;
import com.zhou.project.modules.circle.circlePostsYes.entity.PostYes;
import com.zhou.project.modules.system.user.entity.SysUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PostsYesDao extends BaseMapper<PostYes> {

    @Select("SELECT count(*) FROM ucc_circle_posts_yes where posts_id=#{PostsId} and delete_flag=0")
    long queryYse(int PostsId);

    @Select("SELECT count(*) FROM ucc_circle_posts_yes where posts_id=#{postsId} and user_id=#{userId} and delete_flag=0")
    int oneYes(int postsId,int userId);

    @Update("update ucc_circle_posts_yes set delete_flag=1 where user_id=#{userId} and posts_id=#{postsId}")
    void noYes(int postsId,int userId);

    @Select("select id,nick from system_user_info where id in(select user_id from ucc_circle_posts_yes where created_by =#{userId} and delete_flag=0) limit #{sizeCount}")
    @ResultType(SysUser.class)
    List<SysUser> queryUser(int userId,int sizeCount);

    @Select("select name,id from ucc_circle_type_posts where id in(select posts_id from ucc_circle_posts_yes where user_id=#{userId} and delete_flag=0) limit #{sizeCount}")
    @ResultType(CircleGroupPosts.class)
    List<CircleGroupPosts> queryPosts(int userId,int sizeCount);

    @Delete("delete from ucc_circle_posts_yes where posts_id=#{postsId} and user_id=${userId}")
    int deleteTrue(int postsId, int userId);

}
